<%@page import="java.rmi.RemoteException"%>
<%@page import="java.util.Date"%>
<%@page import="javax.xml.ws.Response"%>
<%@page import="exception.NotRegisteredException"%>
<%@page import="java.rmi.Naming"%>
<%@page import="server.ForumHandlerInt"%>
<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- initialize class parameters -->






<html xmlns="http://www.w3.org/1999/xhtml">
<head>


<!-- script for validating forms fields are all filled -->
<script type="text/javascript">
function validate_form ( )
{
    valid = true;

    if (document.registrationForm.userName.value == "")
	  {
	  alert("username must be filled out");
	  return false;
	  } 
	if (document.registrationForm.password.value == "")
	  {
	  alert("password must be filled out");
	  return false;
	  }
	var validId = document.registrationForm.id.value;
	if (validId == "")
	  {
	  alert("id must be filled out");
	  return false;
	  }
	if (isNaN(validId))
	  {
	  alert("Not a valid id number");
	  return false;
	  }
	if (document.registrationForm.firstName.value == "")
	  {
	  alert("first name must be filled out");
	  return false;
	  }
	if (document.registrationForm.lastName.value == "")
	  {
	  alert("last name must be filled out");
	  return false;
	  }
	var validEmail = document.registrationForm.email.value;
	if (validEmail == "")
	  {
	  alert("email must be filled out");
	  return false;
	  }
	var atpos=validEmail.indexOf("@");
	var dotpos=validEmail.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=validEmail.length)
	  {
	  alert("Not a valid e-mail address");
	  return false;
	  }
   
    var result = loadXMLDoc();
    
    if (result=="false")
    	return false;
    
    document.getElementById("myDiv").innerHTML=result;
  //  alert(result);
   var flag = document.getElementById("userAu").innerHTML;
  //  alert(flag);
    if(flag != "ok")
    	return false;
  
    return valid;
}
</script>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="screenStyle.css" rel="stylesheet" type="text/css" />
</head>

<body id="body">


	<script type="text/javascript">
function loadXMLDoc()
{
	
var xmlhttp;
var params;
params = "userName="+document.registrationForm.userName.value+
	"&password="+document.registrationForm.password.value+
	"&id="+document.registrationForm.id.value+
	"&firstName="+document.registrationForm.firstName.value+
	"&lastName="+document.registrationForm.lastName.value+
	"&email="+document.registrationForm.email.value
	;


			
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  
xmlhttp.open("POST","regValidation.jsp",false);
//http.open("POST", "userValidation.jsp", true);

//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");


xmlhttp.send(params);


if (xmlhttp.status != 200)
{
	document.write(xmlhttp.responseText);
	return "false"
}


return xmlhttp.responseText;
}
</script>






	<h1>REGISTRATION SCREEN</h1>
	<div id="myDiv"></div>

	
	<form action="frames.jsp" method="post" name="registrationForm"
		onsubmit="return validate_form ( );">
				<table width="200" border="0">
		      <tr>
		        <th scope="row">username</th>
		        <td><input name="userName" type="text" value="" maxlength="45"/></td>
		      </tr>
		      <tr>
		        <th scope="row">password</th>
		        <td><input name="password" type="password" value="" maxlength="45"/></td>
		      </tr>
			  <tr>
		        <th scope="row">id</th>
		        <td><input name="id" type="text" value="" maxlength="9"/></td>
		      </tr>
		      <tr>
		        <th scope="row">firstName</th>
		        <td><input name="firstName" type="text" value="" maxlength="45" /></td>
		      </tr>
		      <tr>
		        <th scope="row">lastName</th>
		        <td><input name="lastName" type="text" value="" maxlength="45"/></td>
		      </tr>
		      <tr>
		        <th scope="row">email</th>
		        <td><input name="email" type="text" value="" maxlength="45"/></td>
		      </tr>
		    </table>
		    	<input name="register" type="submit" value="register" /> <input
					name="cancle" type="button" value="cancle"
					onclick="window.open('index.jsp', '_self')" />
			</form>
</body>

</html>